/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.util.Random;

/**
 *
 * @author Stupi
 */
public class PointsPanel extends javax.swing.JPanel {

    /**
     * Creates new form PointsPanel
     */
    private int[] xCoordinates;
    private int[] yCoordinates;
    
    private int[] clusterLimits; 
    
    boolean firstTime;
    private Color [] colours;
    
    public PointsPanel(int [] xCoordinates, int [] yCoordinates, int [] clusterLimits) {
        initComponents();

        this.xCoordinates = xCoordinates;
        this.yCoordinates = yCoordinates;
        this.clusterLimits = clusterLimits;
        setVisible(true);
        firstTime = true;
        colours = new Color[6];
        colours[0] = Color.BLUE;
        colours[1] = Color.YELLOW;
        colours[2] = Color.RED;
        colours[3] = Color.GREEN;
        colours[4] = Color.ORANGE;
        colours[5] = Color.BLACK;
        
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g); 
        Graphics2D g2d = (Graphics2D) g; 
        int oldLimit = 0;
        for (int i = 0; i < clusterLimits.length; i++) {
            int limit = clusterLimits[i];
            g2d.setColor(colours[i]);
           
            for (int j = oldLimit; j < limit; j++) {
                int x = xCoordinates[j];
                int y = yCoordinates[j];
                             
                g2d.drawLine(x-1, y-1, x+1, y+1);
                g2d.drawLine(x-1, y+1, x+1, y-1);
                g2d.drawLine(x-1, y, x+1, y);
                g2d.drawLine(x, y+1, x, y-1);
                
                oldLimit = limit;
            }
        }
        
        
      
        
    }

    
    protected Color setDefaultColor () {
        Random random = new Random();
        
        int red = random.nextInt(255);
        int green = random.nextInt(255);
        int blue = random.nextInt(255);
        
        Color color = new Color(red, green, blue);
        
        return color;
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
